package com.greensam.pixelengine.event.listener;

import com.greensam.pixelengine.event.pixel.PixelEvent;
import com.greensam.pixelengine.event.pixel.PixelEventBus;
import com.greensam.pixelengine.event.pixel.PixelEventType;
import com.greensam.pixelengine.pojo.vo.user.response.LoginUserVo;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author Ma Chengrui
 * @since 2025/10/30 17:46
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class UserEventListener {

    private final PixelEventBus pixelEventBus;

    @PostConstruct
    public void init() {
        pixelEventBus.subscribe(PixelEventType.USER_LOGIN.getCode(), this::onUserLogin);
    }

    private void onUserLogin(PixelEvent pixelEvent) {
        LoginUserVo params = pixelEvent.getWrappedEvent();
        log.info("用户登录：{}", params.getName());
    }

}
